﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using laba2.Context;
using laba2.Entity;
using laba2.Repository.IRepository;

namespace laba2.Repository.DAO
{
    public class AchivementDAO:GenericDAO<Achivement>,IAchivementRepository
 {
     public List<Achivement> GetByStudent(Student student)
     {
         using (var context=new Lab3DBContext())
         {
             return (from achivement in context.Achivements
                     where achivement.Student == student
                     select achivement).ToList();
         }
     }

     public List<Achivement> GetByCourse(Course course)
     {
         using (var context = new Lab3DBContext())
         {
             return (from achivement in context.Achivements
                     where achivement.Task.Course == course
                     select achivement).ToList();
         }
     }

     public List<Achivement> GetByStudentAndCourse(Student student, Course course)
     {
         using (var context = new Lab3DBContext())
         {
             return (from achivement in context.Achivements
                     where achivement.Student == student && achivement.Task.Course == course
                     select achivement).ToList();
         }
     }

     public List<Achivement> GetByStudentId(int id)
     {
         using (var context = new Lab3DBContext())
         {
             return (from achivement in context.Achivements
                     where achivement.Student.Id == id
                     select achivement).ToList();
         }
     }

     public List<Achivement> GetByStudentIdAndCourseId(int studentId, int courseId)
     {
         using (var context = new Lab3DBContext())
         {
             return (from achivement in context.Achivements
                     where achivement.Student.Id == studentId && achivement.Task.Course.Id == courseId
                     select achivement).ToList();
         }
     }
 }
}
